﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Condimar.Entities;

namespace Condimar.Repository
{
    public class MarcaDAO:MasterRepository, IMarcaDAO
    {
        public List<Marca> GetAllFromMarcas()
        {
            var query = from c in context.Marcas
                        select c;
            return query.ToList();
        }

        public List<Marca> GetFromClienteByDescripcion(string descripcion)
        {
            if (descripcion != "")
            {
                var query = from m in context.Marcas
                            where m.Descripcion.ToUpper().Contains(descripcion.ToUpper())
                            select m;
                return query.ToList();
            }
            else
            {
                var query1 = from c in context.Marcas
                             select c;
                return query1.ToList();
            }
        }

        public Marca GetFromMarcaById(int id)
        {
            return context.Marcas.Find(id);
        }

        public void AddMarca(Marca marca)
        {
            context.Marcas.Add(marca);
            context.SaveChanges();
        }

        public void UpdateMarca(Marca marca)
        {
            context.Entry(marca).State = System.Data.EntityState.Modified;
            context.SaveChanges();
        }

        public void RemoveMarca(int id)
        {
            var existe = from c in context.Marcas
                         where c.Id.Equals(id)
                         select c;

            context.Marcas.Remove(existe.SingleOrDefault());
            context.SaveChanges();
        }
    }
}
